package me.shurufa.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.widget.LinearLayout;

import butterknife.Bind;
import me.shurufa.R;
import me.shurufa.utils.Global;

/**
 * 闪屏界面
 *
 * @FileName: me.shurufa.activities.SplashActivity.java
 * @author: kHRYSTAL
 * @email: 723526676@qq.com
 * @date: 2016-01-14 15:52
 */
public class SplashActivity extends BaseActivity {

  @Bind(R.id.splash_root)
  LinearLayout rootLayout;

  private static final int sleepTime = 2000;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    activity_layout_res = R.layout.activity_splash;
    super.onCreate(savedInstanceState);
    Global.appInit(this);
    // 淡入效果
    AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
    animation.setDuration(2000);
    rootLayout.startAnimation(animation);
  }

  @Override
  protected void onStart() {
    super.onStart();
      new Thread(new Runnable() {
        @Override
        public void run() {
          // TODO 判断用户是否登录 如果登录了进MainActivity否则进入LoginActivity
          try {
            Thread.sleep(sleepTime);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          if (Global.isLoggedIn()) {
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            finish();
          } else {
            startActivity(new Intent(SplashActivity.this, LoginActivity.class));
            finish();
          }
        }
      }).start();
  }
}
